<template>
	<view class="content">
		<view>
			<u-swipe-action :show="item.show" :index="index" v-for="(item, index) in list" :key="item.id"
				@click="click(item.id)" @open="open" :options="options">
				<view class="message u-border-bottom" @click="go(item.targetId,item.messageType,item.id)">
					<image v-if="item.isRead==0 " style="width: 42rpx; height: 49rpx;"
						src="https://xiyanluo.oss-cn-beijing.aliyuncs.com/%E8%8D%94%E8%87%B4%E5%AE%B6%E6%95%99/message.png" />
					<image v-if="item.isRead==1" style="width: 42rpx; height: 49rpx;" src="@/static/image/read.png" />
					<text>{{item.title}}
						<text v-if="item.messageType==4||item.messageType==3"> <text>点击</text><text
								style="color: #ff7966;margin: 0 10rpx;">{{item.messageType==4?'课程反馈':''}}</text>
							<text :style="{color: item.messageType==3?'#ff7966':''}">查看详情</text>
						</text>
					</text>
				</view>
			</u-swipe-action>
			<u-empty text="暂无消息" v-if="list.length === 0" mode="list"></u-empty>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				list: [],
				disabled: false,
				btnWidth: 180,
				show: false,
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}]
			}
		},
		onShow() {
			this.getNotice()
		},
		methods: {
			// 通知
			async getNotice() {
				this.list = await this.$u.api.getNotice()
				this.list.map(item => {
					if (item.messageType == 4 || item.messageType == 3) {
						let a = item.title.indexOf('，')
						item.title = item.title.substring(0, a)
					}

				})

			},
			go(id, type, reade) {
				this.$u.api.updRead({
					id: reade
				})
				console.log(id, type);
				if (type == 4) {
					uni.navigateTo({
						url: `/pages/invent/courseDes?backId=${id}`
					})
				} else {
					uni.navigateTo({
						url: `/pages/invent/demandDel?id=${id}`
					})
				}
			},
			async click(id) {
				console.log(id);
				const res = await this.$u.api.delNum({
					id: id
				})
				this.$u.toast('删除成功')
				this.getNotice()
				// if (index1 == 1) {
				// 	this.list.splice(index, 1);
				// 	this.$u.toast(`删除了第${index}个cell`);
				// } else {
				// 	this.list[index].show = false;
				// 	this.$u.toast(`收藏成功`);
				// }
			},
			// 如果打开一个的时候，不需要关闭其他，则无需实现本方法
			open(index) {
				console.log(index);
				// 先将正在被操作的swipeAction标记为打开状态，否则由于props的特性限制，
				// 原本为'false'，再次设置为'false'会无效
				this.list[index].show = true;
				this.list.map((val, idx) => {
					if (index != idx) this.list[idx].show = false;
				})
			}
		}
	}
</script>

<style lang="scss">
	.item {
		display: flex;
		padding: 20rpx;
	}

	// image {
	// 	width: 120rpx;
	// 	flex: 0 0 120rpx;
	// 	height: 120rpx;
	// 	margin-right: 20rpx;
	// 	border-radius: 12rpx;
	// }
	/deep/.u-btn-text {
		top: 33% !important;
	}

	.title {
		text-align: left;
		font-size: 28rpx;
		color: $u-content-color;
		margin-top: 20rpx;
	}

	.content {

		.message {
			padding-left: 47rpx;
			height: 127rpx;
			border-bottom: 1px solid #eeeeee;
			display: flex;
			align-items: center;

			text {
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;
			}
		}

	}
</style>